﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Interfaces
{
    public interface IPositionData
    {
        byte FormatCode { get; }
    }

    public interface IAbsoluteData : IPositionData
    {
        double Latitude { get; set; }
        double Longitude { get; set; }
        DateTime Time { get; set; }
    }

    /// <summary>
    /// Interface to define common proximity entity for event notifications
    /// The hash value identifies the radio source unambiguously
    /// </summary>
    public interface IProximityData : IPositionData
    {
        string HashValue { get; }
        string Name { get; }
        int RelativeSignalStrength { get; }
    }

    public class BluetoothData : IProximityData
    {
        public byte[] BT_ADDR { get; set; }
        public string Name { get; set; }
        public byte Rssi { get; set; }

        #region IProximityData Members

        string IProximityData.HashValue
        {
            get
            {
                return BitConverter.ToString(BT_ADDR);
            }
        }

        public int RelativeSignalStrength
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region IPositionData Members

        public byte FormatCode
        {
            get { return 23; }
        }

        #endregion
    }

    public class CellData : IProximityData
    {
        public int Id { get; set; }
        public int Lac { get; set; }
        public int Mcc { get; set; }
        public int Mnc { get; set; }
        public int SignalStrength { get; set; }

        #region IProximityData Members

        public string HashValue
        {
            get { return this.Mcc + "-" + this.Mnc + "-" + this.Id; }
        }

        public string Name { get; set; }

        public int RelativeSignalStrength
        {
            get { return SignalStrength; } // TODO: scale to 0..100 interval
        }

        #endregion

        #region IPositionData Members

        public byte FormatCode
        {
            get { return 21; }
        }

        #endregion
    }

    public class WifiData : IProximityData
    {
        public byte[] MacAddress { get; set; }
        public int Rssi { get; set; }

        #region IProximityData Members

        public string HashValue
        {
            get { return BitConverter.ToString(MacAddress); }
        }

        public string Name { get; set; }

        public int RelativeSignalStrength //a wifinél elméletileg -10 és -113 dB-es jelek lehetnek.
        {
            get
            {
                int rel =110+Rssi;

                if (rel > 100)
                    return 100;
                else if (rel < 0)
                    return 0;
                else return rel;            
            } // TODO: implement this!
        }

        #endregion

        #region IPositionData Members

        public byte FormatCode
        {
            get { return 22; }
        }

        #endregion
    }

    public class GPSData : IAbsoluteData
    {
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public DateTime Time { get; set; }
        public static GPSData Empty
        {
            get { return new GPSData() { Latitude = double.NaN, Longitude = double.NaN, Time = DateTime.Now}; }
        }

        #region IPositionData Members

        public byte FormatCode
        {
            get { return 11; }
        }

        #endregion
    }
}
